fix: non HTTP requests are undefined in built-in AuthGuard #121
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all, nice to meet you and these project.
the AuthGuard also comes into operation when requests that are not HTTP arrive such as amqp (rabbit MQ).
In fact, there are modules such as
@golevelup/nestjs-rabbitmq
that provide a decorator that works in a similar way to the http core decorator provided by nest, and therefore subject to middleware.The module's built-in AuthGuard does not detect the undefined returned by the extractRequest function, causing an exception just after reading request.cookies.
the workaround I found immediately is to use the decorator
@Unprotected()
thus entering the conditionisUnprotected
The real solution instead could be to insert a simple condition whereby if request is undefined, the guard returns true (because it is out of its competence).
I am therefore sending you a pr with the solution I have undertaken, hoping that from your point of view it can be really decisive
regards